<template>
  <div class="detail">
    <!-- 这写头部 -->
    <van-nav-bar
      title="面经详情"
      left-text="返回"
      @click-left="$router.go(-1)"
    />

    <h1>{{ obj.stem }}</h1>

    <div class="info">
      <span>{{ obj.createdAt }}</span>
      <span>|</span>
      <span>{{ obj.views }} 浏览量</span>
      <span>|</span>
      <span>{{ obj.likeCount }} 点赞数</span>
    </div>

    <div class="qian">
      <img :src="obj.avatar" alt="" />
      <span>{{ obj.creator }}</span>
    </div>

    <div class="content" v-html="obj.content"></div>

    <!-- 一个喜欢按钮一个收藏按钮 -->
    <div class="btns">
      <van-button class="a" icon="like-o" color="#fec635" round type="info">
      </van-button>
      <van-button class="b" icon="star-o" color="#ccc" round type="info">
      </van-button>
    </div>
  </div>
</template>

<script>
import axios from "axios";

export default {
  name: "HmDetail",
  created() {
    this.getDetail(this.$route.params.id);
  },
  data() {
    return {
      obj: {},
    };
  },
  methods: {
    fn() {
      console.log("点击了");
      // this.$router.back();
      this.$router.go(-1);
    },

    async getDetail(id) {
      const res = await axios({
        url: `http://interview-api-t.itheima.net/h5/interview/show?id=${id}`,
        headers: {
          Authorization: `Bearer ${localStorage.getItem(`token`)}`,
        },
      });
      console.log(res);
      this.obj = res.data.data;
    },
  },
};
</script>

<style lang="less" scoped>
.info {
  color: rgb(153, 153, 153);
}
.qian {
  display: flex;
  align-items: center;

  img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
  }
  span {
    // 灰色
    color: rgb(153, 153, 153);
    font-size: 14px;
  }
}

.content {
  text-indent: 2em;
}
.btns {
  width: 100%;
  position: relative;

  .a {
    margin: 0 10px;
    position: absolute;
    right: 60px;
  }
  .b {
    margin: 0 10px;
    position: absolute;
    right: 0;
  }
}
</style>
